package top.laoshuzi.cloudplatform.camera.ui;


import android.os.Bundle;
import android.app.Fragment;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import top.laoshuzi.cloudplatform.R;
import top.laoshuzi.cloudplatform.camera.CameraHandler;

/**
 * A simple {@link Fragment} subclass.
 */
public class CameraFragment extends Fragment {

    CameraHandler cameraHandler;

    Button openCamera;
    Button closeCamera;
    Button startRec;
    Button stopRec;
    Button takePic;

    public CameraFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_camera, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        openCamera = view.findViewById(R.id.openCamera);
        closeCamera = view.findViewById(R.id.closeCamera);
        startRec = view.findViewById(R.id.startRec);
        stopRec = view.findViewById(R.id.stopRec);
        takePic = view.findViewById(R.id.takePic);

        openCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraHandler.openCamera();
            }
        });
        closeCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraHandler.closeCamera();
            }
        });
        startRec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraHandler.startRecordingVideo();
            }
        });
        stopRec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraHandler.stopRecordingVideo();
            }
        });
        takePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraHandler.takePicture();
            }
        });

        cameraHandler = CameraHandler.getInstance();

    }
}
